import { DIvHtml } from './DIvHtml'
const { mars3d } = window
export const Mars3DRender = ({ map, gra, data }) => {
    Object.keys(data).forEach(key => {
        const { uuid, type, title, coordinates, isEnable, ...style } = data[key]
        if (type === 'kml') {
            const { url, ...styleOptions } = style
            map.addLayer(
                new mars3d.layer.KmlLayer({ id: uuid, url, symbol: { styleOptions }, show: isEnable, attr: title }),
            )
        }
        if (type === 'tileset') {
            const { uuid: id, title: name, isEnable: show, type: popup, ...tilesetData } = data[key]
            map.addLayer(new mars3d.layer.TilesetLayer({ id, name, show, popup, ...tilesetData }))
        }
        if (coordinates) {
            switch (type) {
                case 'labelP':
                    gra.addGraphic(
                        new mars3d.graphic.LabelPrimitive({
                            id: uuid,
                            position: coordinates[0],
                            style,
                            show: isEnable,
                            attr: title,
                        }),
                    )
                    break
                case 'pointP':
                    gra.addGraphic(
                        new mars3d.graphic.PointPrimitive({
                            id: uuid,
                            position: coordinates[0],
                            style,
                            show: isEnable,
                            attr: title,
                        }),
                    )
                    break
                case 'billboardP':
                    gra.addGraphic(
                        new mars3d.graphic.BillboardPrimitive({
                            id: uuid,
                            position: coordinates[0],
                            style,
                            show: isEnable,
                            attr: title,
                        }),
                    )
                    break
                case 'tetrahedron':
                    gra.addGraphic(
                        new mars3d.graphic.Tetrahedron({
                            id: uuid,
                            position: coordinates[0],
                            style,
                            show: isEnable,
                            attr: title,
                        }),
                    )
                    break
                case 'div':
                    gra.addGraphic(
                        new mars3d.graphic.DivGraphic({
                            id: uuid,
                            position: coordinates,
                            style: { html: DIvHtml[style.selectDome](style.selectText), ...style },
                            popup: 'DIV',
                        }),
                    )
                    break

                case 'divBoderLabel':
                    gra.addGraphic(
                        new mars3d.graphic.DivBoderLabel({
                            id: uuid,
                            position: coordinates,
                            style,
                            show: isEnable,
                            attr: title,
                        }),
                    )
                    break
                case 'divUpLabel':
                    gra.addGraphic(
                        new mars3d.graphic.DivUpLabel({
                            id: uuid,
                            position: coordinates,
                            style,
                            show: isEnable,
                            attr: title,
                        }),
                    )
                    break
                case 'divLightPoint':
                    gra.addGraphic(
                        new mars3d.graphic.DivLightPoint({
                            id: uuid,
                            position: coordinates,
                            style,
                            show: isEnable,
                            attr: title,
                        }),
                    )
                    break
                case 'polylineP':
                    gra.addGraphic(
                        new mars3d.graphic.PolylinePrimitive({
                            id: uuid,
                            positions: coordinates,
                            style,
                            show: isEnable,
                            attr: title,
                        }),
                    )
                    break
                case 'curve':
                    gra.addGraphic(
                        new mars3d.graphic.CurveEntity({
                            id: uuid,
                            positions: coordinates,
                            style,
                            show: isEnable,
                            attr: title,
                        }),
                    )
                    break
                case 'polylineVolumeP':
                    gra.addGraphic(
                        new mars3d.graphic.PolylineVolumePrimitive({
                            id: uuid,
                            positions: coordinates,
                            style,
                            show: isEnable,
                            attr: title,
                        }),
                    )
                    break
                case 'corridorP':
                    gra.addGraphic(
                        new mars3d.graphic.CorridorPrimitive({
                            id: uuid,
                            positions: coordinates,
                            style,
                            show: isEnable,
                            attr: title,
                        }),
                    )
                    break
                case 'wallP':
                    gra.addGraphic(
                        new mars3d.graphic.WallPrimitive({
                            id: uuid,
                            positions: coordinates,
                            style,
                            show: isEnable,
                            attr: title,
                        }),
                    )
                    break
                case 'diffuseWall':
                    gra.addGraphic(
                        new mars3d.graphic.DiffuseWall({
                            id: uuid,
                            positions: coordinates,
                            style,
                            show: isEnable,
                            attr: title,
                        }),
                    )
                    break
                case 'scrollWall':
                    gra.addGraphic(
                        new mars3d.graphic.ScrollWall({
                            id: uuid,
                            positions: coordinates,
                            style,
                            show: isEnable,
                            attr: title,
                        }),
                    )
                    break
                case 'thickWall':
                    gra.addGraphic(
                        new mars3d.graphic.ThickWall({
                            id: uuid,
                            positions: coordinates,
                            style,
                            show: isEnable,
                            attr: title,
                        }),
                    )
                    break
                case 'polygonP':
                    gra.addGraphic(
                        new mars3d.graphic.PolygonPrimitive({
                            id: uuid,
                            positions: coordinates,
                            style,
                            show: isEnable,
                            attr: title,
                        }),
                    )
                    break
                case 'rectangleP':
                    gra.addGraphic(
                        new mars3d.graphic.RectanglePrimitive({
                            id: uuid,
                            positions: coordinates,
                            style,
                            show: isEnable,
                            attr: title,
                        }),
                    )
                    break
                case 'circleP':
                    gra.addGraphic(
                        new mars3d.graphic.CirclePrimitive({
                            id: uuid,
                            positions: coordinates,
                            style,
                            show: isEnable,
                            attr: title,
                        }),
                    )
                    break
                case 'ellipse':
                    gra.addGraphic(
                        new mars3d.graphic.EllipseEntity({
                            id: uuid,
                            positions: coordinates,
                            style,
                            show: isEnable,
                            attr: title,
                        }),
                    )
                    break
                case 'sector':
                    gra.addGraphic(
                        new mars3d.graphic.Sector({
                            id: uuid,
                            positions: coordinates,
                            style,
                            show: isEnable,
                            attr: title,
                        }),
                    )
                    break
                case 'regular':
                    gra.addGraphic(
                        new mars3d.graphic.Regular({
                            id: uuid,
                            positions: coordinates,
                            style,
                            show: isEnable,
                            attr: title,
                        }),
                    )
                    break
                case 'straightArrow':
                    gra.addGraphic(
                        new mars3d.graphic.StraightArrow({
                            id: uuid,
                            positions: coordinates,
                            style,
                            show: isEnable,
                            attr: title,
                        }),
                    )
                    break
                case 'fineArrow':
                    gra.addGraphic(
                        new mars3d.graphic.FineArrow({
                            id: uuid,
                            positions: coordinates,
                            style,
                            show: isEnable,
                            attr: title,
                        }),
                    )
                    break
                case 'fineArrowYW':
                    gra.addGraphic(
                        new mars3d.graphic.FineArrowYW({
                            id: uuid,
                            positions: coordinates,
                            style,
                            show: isEnable,
                            attr: title,
                        }),
                    )
                    break
                case 'attackArrow':
                    gra.addGraphic(
                        new mars3d.graphic.AttackArrow({
                            id: uuid,
                            positions: coordinates,
                            style,
                            show: isEnable,
                            attr: title,
                        }),
                    )
                    break
                case 'attackArrowPW':
                    gra.addGraphic(
                        new mars3d.graphic.AttackArrowPW({
                            id: uuid,
                            positions: coordinates,
                            style,
                            show: isEnable,
                            attr: title,
                        }),
                    )
                    break
                case 'attackArrowYW':
                    gra.addGraphic(
                        new mars3d.graphic.AttackArrowYW({
                            id: uuid,
                            positions: coordinates,
                            style,
                            show: isEnable,
                            attr: title,
                        }),
                    )
                    break
                case 'doubleArrow':
                    gra.addGraphic(
                        new mars3d.graphic.DoubleArrow({
                            id: uuid,
                            positions: coordinates,
                            style,
                            show: isEnable,
                            attr: title,
                        }),
                    )
                    break
                case 'gatheringPlace':
                    gra.addGraphic(
                        new mars3d.graphic.GatheringPlace({
                            id: uuid,
                            positions: coordinates,
                            style,
                            show: isEnable,
                            attr: title,
                        }),
                    )
                    break
                case 'boxP':
                    gra.addGraphic(
                        new mars3d.graphic.BoxPrimitive({
                            id: uuid,
                            positions: coordinates,
                            style,
                            show: isEnable,
                            attr: title,
                        }),
                    )
                    break
                case 'cylinderP':
                    gra.addGraphic(
                        new mars3d.graphic.CylinderPrimitive({
                            id: uuid,
                            positions: coordinates,
                            style,
                            show: isEnable,
                            attr: title,
                        }),
                    )
                    break
                case 'lightCone':
                    gra.addGraphic(
                        new mars3d.graphic.LightCone({
                            id: uuid,
                            positions: coordinates,
                            style,
                            show: isEnable,
                            attr: title,
                        }),
                    )
                    break
                case 'ellipsoidP':
                    gra.addGraphic(
                        new mars3d.graphic.EllipsoidPrimitive({
                            id: uuid,
                            positions: coordinates,
                            style,
                            show: isEnable,
                            attr: title,
                        }),
                    )
                    break
                case 'pointLight':
                    gra.addGraphic(
                        new mars3d.graphic.PointLight({
                            id: uuid,
                            positions: coordinates,
                            style,
                            show: isEnable,
                            attr: title,
                            popup: 'pointLight',
                        }),
                    )
                    break
                case 'spotLight':
                    gra.addGraphic(
                        new mars3d.graphic.SpotLight({
                            id: uuid,
                            positions: coordinates,
                            style,
                            show: isEnable,
                            attr: title,
                            popup: 'spotLight',
                        }),
                    )
                    break
                case 'modelP':
                    gra.addGraphic(
                        new mars3d.graphic.ModelPrimitive({
                            id: uuid,
                            positions: coordinates,
                            style,
                            show: isEnable,
                            attr: title,
                            popup: 'spotLight',
                        }),
                    )
                    break
                default:
                    console.log('未知元素', type)
                    break
            }
        }
    })
}
